<?php

App::uses('Controller', 'Controller');

class CommonController extends Controller {

    /**
     * 
     */
    public function building() {
        $this->loadModel('Building');
        $id = $this->request->query('id');
        $is_insert = $this->request->query('is_insert');
         $result = array();
        
        if ($id != null) {
            $result = $this->Building->getListBuildingOfCustomer($id);
            
        }
        if ($is_insert !=='' && $is_insert != 1) {
            $result[0] = 'すべて';
        }
        ksort($result);
        echo json_encode($result);
        exit();
    }

    /**
     * 
     */
    public function map($address = "") {
        $this->layout = false;
        $map_options = array(
            "id" => "map_canvas",
            "width" => "750px",
            "height" => "380px",
            "zoom" => 16,
            "type" => "ROADMAP",
            "localize" => false,
            "address" => $address,
            "marker" => true,
            "markerIcon" => "http://maps.google.com/mapfiles/marker.png",
            "markerShadow" => "http://maps.google.com/mapfiles/shadow50.png",
            "infoWindow" => true,
            "windowText" => $address
        );
        $this->set('map_options', $map_options);
    }

    /**
     * 
     */
    public function download() {
        App::import('Vendor', 'chip_download', array('file' => 'chip_download.php'));
        $download_path = APP . "webroot" . DS . 'files' . DS;
        //var_dump($download_path);
        //die();
        $args = array(
            'download_path' => $download_path,
            'file' => 'ocxSetup.zip',
            'extension_check' => false,
            'referrer_check' => FALSE,
            'referrer' => NULL,
        );
        $download = new chip_download($args);
        $download_hook = $download->get_download_hook();
        if ($download_hook['download'] == TRUE) {
            $download->get_download();
        }
    }
    
    /**
     * 
     */
    public function get_camera(){
        /*
        $this->autoRender=false;
        $this->loadModel('Camera');
        if(isset($_POST['CustId']))
            $CustId=$_POST['CustId'];
        if(!empty($CustId)){
            $cameras=$this->Camera->getListCamera($CustId);
            echo json_encode($cameras);
        }*/
    }
    
    /**
     * 
     */
    public function ping(){
        $file_ping = PATH_BACKGROUND."ping.php";
        //pclose(popen('start php -f "'.$file_ping.'" ',"r"));
        exec('php -f "'.$file_ping.'" > /dev/null &');
        die('12');
    }

}